package com.atguigu.spzx.manager.service.product.impl;

import com.atguigu.spzx.manager.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manager.service.product.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mahone
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {

    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    @Override
    public PageInfo<CategoryBrand> getCategoryBrandPageList(Integer pageNum, Integer pageSize, CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(pageNum,pageSize);
        List<CategoryBrand> categoryBrandList = categoryBrandMapper.selectCategoryBrandPageList(categoryBrandDto);
        return new PageInfo<>(categoryBrandList);
    }

    @Override
    public void insertCategoryBrandById(CategoryBrand categoryBrand) {
        categoryBrandMapper.insertCategoryBrandById(categoryBrand);
    }

    @Override
    public void updateCategoryBrandById(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateCategoryBrandById(categoryBrand);
    }

    @Override
    public void deleteCategoryBrandById(Long id) {
        categoryBrandMapper.deleteCategoryBrandById(id);
    }

    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        List<Brand> brandList = categoryBrandMapper.selectBrandByCategoryId(categoryId);
        return brandList;
    }
}
